package com.handtransaction.dao;

import com.handtransaction.entity.Administrator;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AdministratorDao {

    //根据id查询管理员
    @Select("SELECT * FROM administrators WHERE aid=#{aid}")
    Administrator ReadAdminibyId(Integer aid);

    //根据名称查找管理员
    @Select("SELECT * FROM administrators WHERE aname=#{aname}")
    Administrator ReadAdminByName(String aname);

    //根据对象查找管理员
    @Select("SELECT * FROM administrators WHERE aname=#{aname} or aid=#{aid}")
    Administrator readAdminByAdmin(Administrator administrator);

    //查看所有普通管理员
    @Select("select * from administrators where apower = 'general'")
    List<Administrator> readAllGeneralAdmins();

    //修改管理员个人信息
    @Update("update administrators set " +
    "apassword=#{apassword},aname=#{aname},afaculty=#{afaculty},aphone=#{aphone},aheadsrc=#{aheadsrc} where aid=#{aid}")
    int updateAdminInfo(Administrator administrator);

    //新增管理员
    @Insert("insert into administrators(aname,apassword,afaculty,aphone,apower) values(#{aname},#{apassword},#{afaculty},#{aphone},#{apower})")
    int createAdminByRootAdmin(Administrator administrator);

    //删除管理员
    @Delete("delete from administrators where aid=#{aid}")
    int deleteAdminById(Integer aid);

}
